package com.example.springboot.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * Created by wuning at 2018/8/31 14:01
 **/
public class MD5PasswordEncoder implements PasswordEncoder {

    private final Logger log = LoggerFactory.getLogger(getClass());

    @Override
    public String encode(CharSequence rawPassword) {

        String md5 = MD5Util.getMD5(rawPassword.toString());

        log.info("encode>>rawPassword="+rawPassword+",md5="+md5);

        return md5;
    }

    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {

        log.info("matches>>encodedPassword="+encodedPassword);
        return encodedPassword.equalsIgnoreCase(encode(rawPassword.toString()));
    }
}
